﻿using System;
using System.Collections.Generic;
using System.Text;
using MbUnit.Framework;
using MyTestRunner.Domain;
using System.Reflection;
using MyTestRunner.Infrastructure;

namespace MyTestRunner.Tests.Domain
{
    /// <summary>
    /// Specifies how expected exception types should be found.
    /// </summary>
    [TestFixture]
    [TestsOn(typeof(ITestFinder))]
    public abstract class WhenFindingExpectedExceptionTypes
    {
        /// <summary>
        /// Returns the test finder we want to test.
        /// </summary>
        public abstract ITestFinder CreateSut();

        /// <summary>
        /// Returns a test method with an expected exception type.
        /// </summary>
        public abstract MethodInfo GetTestWithExpectedExceptionType();

        /// <summary>
        /// Returns a test method without an expected exception type.
        /// </summary>
        public abstract MethodInfo GetTestWithoutExpectedExceptionType();

        /// <summary>
        /// Given that the test does not have an expected exception type, the method should return false.
        /// </summary>
        [Test]
        public void ShouldReturnFalseWhenTestDoesNotHaveExpectedExceptionType()
        {
            ITestFinder sut = CreateSut();

            MethodInfo methodWithoutExcpectedException = GetTestWithoutExpectedExceptionType();
            Type expectedExceptionType;
            Assert.IsFalse(sut.TryGetExpectedExceptionType(methodWithoutExcpectedException, out expectedExceptionType));
            Assert.IsNull(expectedExceptionType);
        }

        public void ShouldReturnTrueGivenTestDoesHaveAnExpectedExceptionType()
        {
            ITestFinder sut = CreateSut();

            MethodInfo methodWithExcpectedException = GetTestWithoutExpectedExceptionType();
            Type expectedExceptionType;
            Assert.IsTrue(sut.TryGetExpectedExceptionType(methodWithExcpectedException, out expectedExceptionType));
            Assert.IsNotNull(expectedExceptionType);
        }
    }
}
